/*******************************************************************************
 * Copyright (c) 2010 Gary Yund {OTHER COPYRIGHT OWNERS}.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Gary Yund - initial API and implementation and/or initial documentation
 *******************************************************************************/

#import "BB_Logger.h"

#import "BB_SynthesizeSingleton.h"



@implementation BB_Logger

BB_SYNTHESIZE_SINGLETON_FOR_CLASS(BB_Logger);

@synthesize logLevel;

-(id)init
{
    [super init];
    
    // Initialize log level to zero
    logLevel = BB_LOG_NONE;
    
    return self;
}

-(void)setLogLevel:(BB_LogLevel_t)level
{
    logLevel = level;
}

-(void)log:(NSString*)string atLevel:(BB_LogLevel_t)level
{
    // APPLY BITMASK TO SEE IF THE DATA SHOULD BE LOGGED
    if( 0 != (logLevel & level))
    {
        switch (level) {
            // COMMON LOG LEVELS
            case BB_LOG_NONE:
                NSLog(@"[NONE-invalid level] %@", string);
                break;
            case BB_LOG_ANY:
                NSLog(@"[ANY-invalid level] %@", string);
                break;
            case BB_LOG_DEBUG:
                NSLog(@"[debug] %@", string);
                break;
            case BB_LOG_ERROR:
                NSLog(@"[error] %@", string);
                break;
            
            // PROGRAM FLOW LOGGING
            case BB_LOG_LOGIC:
                NSLog(@"[logic] %@", string);
                break;
            case BB_LOG_EVENT:
                NSLog(@"[event] %@", string);
                break;
            case BB_LOG_COREDATA:
                NSLog(@"[coredata] %@", string);
                break;
            
            
            case BB_LOG_LIFECYCLE:
                NSLog(@"[lifecycle] %@", string);
                break;
            
            default:
                NSLog(@"[unknown] %@", string);
                break;
        }       
    }
}


@end
